﻿using System;
using System.Collections.Generic;
using Castle.ActiveRecord;
using CosyTrade.Data;
using CosyTrade.Distribution;
using CosyTrade.Financial;
using CosyTrade.Organization;


namespace CosyTrade.Futures
{
    /// <summary>
    /// 订单/出入口单
    /// </summary>
    [AddPropertyChangedNotifyInterface, PropertyChangedNotify]
    [ActiveRecord("tbOrderForm"), Serializable]
    public class OrderForm : BusinessObject
    {
        private readonly Guid primaryKey = Guid.NewGuid();
        [PrimaryKey(PrimaryKeyType.Assigned, "ROWGUID", Access = PropertyAccess.NosetterCamelcase)]
        public override Guid PrimaryKey
        {
            get { return primaryKey; }
        }
        /// <summary>
        /// 订单编号
        /// </summary>
        private string orderId;
        /// <summary>
        /// 订单内容
        /// </summary>
        private IList<OrderFormWares> orderWares = new List<OrderFormWares>();
        /// <summary>
        /// 客户名称
        /// </summary>
        private Client clientName;
        /// <summary>
        /// 送货地址
        /// </summary>
        private string deliverGoodsAddress;
        /// <summary>
        /// 送货人
        /// </summary>
        private Employee deliverGoodsEmp;
        /// <summary>
        /// 下单人
        /// </summary>
        private Employee makeOrder;
        /// <summary>
        /// 下单日期
        /// </summary>
        private DateTime makeOrderDate = DateTime.Now;
        /// <summary>
        /// 预计出货日期
        /// </summary>
        private DateTime shipmentDate;
        /// <summary>
        /// 人货人
        /// </summary>
        private Employee sendGoodser;
        /// <summary>
        /// 发货日期
        /// </summary>
        private DateTime sendGoodsDate;
        /// <summary>
        /// 商品总数
        /// </summary>
        private int waresCount;
        /// <summary>
        /// 订单总价(应付款金额)
        /// </summary>
        private double totalValues;
        /// <summary>
        /// 订单状态
        /// </summary>
        private OrderFormState orderState;
        /// <summary>
        /// 已付款金额
        /// </summary>
        private double hasPayMoney;
        /// <summary>
        /// 付款状态
        /// </summary>
        private PayState orderPayState;
        /// <summary>
        /// 收货人
        /// </summary>
        private Employee reviceGoodser;
        /// <summary>
        /// 收货公司
        /// </summary>
        private Company reviceCompany;
        /// <summary>
        /// 出口单总价
        /// </summary>
        private double exportValues;
        /// <summary>
        /// 出口汇率
        /// </summary>
        private ExchangeRate exchange;

        /// <summary>
        /// 订单编号
        /// </summary>
        [Property]
        public string OrderId
        {
            get { return orderId; }
            set { orderId = value; }
        }

        /// <summary>
        /// 订单内容
        /// </summary>
        [HasAndBelongsToMany(typeof(OrderFormWares), Access = PropertyAccess.NosetterCamelcase, ColumnKey = "orderFormID", ColumnRef = "wareGuid", Table = "tbOrderFormAndWares")]
        public IList<OrderFormWares> OrderWares
        {
            get { return orderWares; }
            set { orderWares = value; }
        }

        /// <summary>
        /// 客户名称
        /// </summary>
        [BelongsTo]
        public Client ClientName
        {
            get { return clientName; }
            set { clientName = value; }
        }

        /// <summary>
        /// 送货地址
        /// </summary>
        [Property]
        public string DeliverGoodsAddress
        {
            get { return deliverGoodsAddress; }
            set { deliverGoodsAddress = value; }
        }

        /// <summary>
        /// 送货人
        /// </summary>
        [BelongsTo]
        public Employee DeliverGoodsEmp
        {
            get { return deliverGoodsEmp; }
            set { deliverGoodsEmp = value; }
        }

        /// <summary>
        /// 下单人
        /// </summary>
        [BelongsTo]
        public Employee MakeOrder
        {
            get { return makeOrder; }
            set { makeOrder = value; }
        }

        /// <summary>
        /// 下单日期
        /// </summary>
        [Property]
        public DateTime MakeOrderDate
        {
            get { return makeOrderDate; }
            set { makeOrderDate = value; }
        }

        /// <summary>
        /// 预计出货日期
        /// </summary>
        [Property]
        public DateTime ShipmentDate
        {
            get { return shipmentDate; }
            set { shipmentDate = value; }
        }

        /// <summary>
        /// 发货人
        /// </summary>
        [BelongsTo]
        public Employee SendGoodser
        {
            get { return sendGoodser; }
            set { sendGoodser = value; }
        }

        /// <summary>
        /// 发货日期
        /// </summary>
        [Property]
        public DateTime SendGoodsDate
        {
            get { return sendGoodsDate; }
            set { sendGoodsDate = value; }
        }

        /// <summary>
        /// 商品总数
        /// </summary>
        [Property]
        public int WaresCount
        {
            get { return waresCount; }
            set { waresCount = value; }
        }

        /// <summary>
        /// 订单总价(应付款金额)
        /// </summary>
        [Property]
        public double TotalValues
        {
            get { return totalValues; }
            set { totalValues = value; }
        }

        /// <summary>
        /// 订单状态
        /// </summary>
        [Property]
        public OrderFormState OrderState
        {
            get { return orderState; }
            set { orderState = value; }
        }

        /// <summary>
        /// 已付款金额
        /// </summary>
        [Property]
        public double HasPayMoney
        {
            get { return hasPayMoney; }
            set { hasPayMoney = value; }
        }

        /// <summary>
        /// 付款状态
        /// </summary>
        [Property]
        public PayState OrderPayState
        {
            get { return orderPayState; }
            set { orderPayState = value; }
        }

        /// <summary>
        /// 收货人
        /// </summary>
        [BelongsTo]
        public Employee ReviceGoodser
        {
            get { return reviceGoodser; }
            set { reviceGoodser = value; }
        }

        /// <summary>
        /// 收货公司
        /// </summary>
        [BelongsTo]
        public Company ReviceCompany
        {
            get { return reviceCompany; }
            set { reviceCompany = value; }
        }

        /// <summary>
        /// 出口单总价
        /// </summary>
        [Property]
        public double ExportValues
        {
            get { return exportValues; }
            set { exportValues = value; }
        }

        /// <summary>
        /// 出口汇率
        /// </summary>
        [BelongsTo]
        public ExchangeRate Exchange
        {
            get { return exchange; }
            set { exchange = value; }
        }
    }
}
